cmake_minimum_required(VERSION 3.8)

project(mds_io LANGUAGES CUDA CXX)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

#${PROJECT_SOURCE_DIR} #当前文件夹路径
#${PROJECT_SOURCE_DIR}/../../../../bin/x64/${CMAKE_BUILD_TYPE})
SET(OPENCV_4 1)

if(WIN32)

    set(PROJECT_PATH "E:/KSGroundSystem/TDAlgorithmProcess")
    if (NOT DEFINED PROJECT_PATH)
      set(PROJECT_PATH "E:/KSGroundSystem/TDAlgorithmProcess")
      #set(PROJECT_PATH "F:/SJ20/TDAlgorithmProcess")
      #set(PROJECT_PATH "D:/KSGroundSystem/TDAlgorithmProcess")
      #set(PROJECT_PATH "/home/htcz/WorkSpace/TDAlgorithmProcess")
      message(${PROJECT_PATH})
    else()
      message(${PROJECT_PATH})
    endif()

    set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /STACK:200000000") #设置栈大小，防止栈溢出
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -openmp")
    link_directories( ${PROJECT_PATH}/lib/x64/${CMAKE_BUILD_TYPE})
    link_directories( ${PROJECT_PATH}/Include/boost_1_76_0/stage/lib)
    include_directories(${PROJECT_PATH}/Include/boost_1_76_0)
    # 设置RUNTIME输出目录,DLL
    set(CMAKE_RUNTIME_OUTPUT_DIRECTORY   ${PROJECT_PATH}/bin/x64/${CMAKE_BUILD_TYPE})
    # 设置库文件的输出目录
    set(LIBRARY_OUTPUT_PATH   ${PROJECT_PATH}/lib/x64/${CMAKE_BUILD_TYPE})

	set(OpenCV_DIR  ${PROJECT_PATH}/Include/opencv4)

    message(${OpenCV_DIR})
		find_package(OpenCV REQUIRED)
		include_directories(${OpenCV_INCLUDE_DIRS})
		link_directories(${OpenCV_LIBRARY_DIRS} ) #path of libvl.so
else()
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -pthread -fopenmp")

  include_directories("/home/htcz/WorkSpace/TDAlgorithmProcess/Include/boost_1_76_0")
  include_directories("/home/htcz/WorkSpace/TDAlgorithmProcess/Include")
  # set(OpenCV_DIR /usr/local/opencv/lib/cmake/opencv4)
  find_package(OpenCV REQUIRED)
  include_directories(${OpenCV_INCLUDE_DIRS})
  link_directories(${OpenCV_LIBRARY_DIRS} ${PROJECT_PATH}/bin_linux) #path of libvl.so

  find_package(CUDA  REQUIRED)
  include_directories("${CUDA_INCLUDE_DIRS}")

endif(WIN32)

set(SOURCES 
    ./io_socket.cpp
    ./io_socket.h

    ./protocol/ks_json.h
    ./protocol/ks_json.cpp
    ./protocol/data_parse.h
    ./protocol/data_parse.cpp

    ./tcp_socket/ring_buffer.cpp 
    ./tcp_socket/ring_buffer.h
    ./tcp_socket/server.cpp
    ./tcp_socket/server.h

    ./web_socket/websocket.cpp
    ./web_socket/websocket.h
    ./web_socket/ws_io_interface.cpp
    ./web_socket/ws_io_interface.h
)
add_library(
	${PROJECT_NAME}
	# SHARED#general *.dll or *.so
	STATIC#general *lib or *.a
  ${SOURCES}
)

target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_11)

if(WIN32)
	target_include_directories(${PROJECT_NAME} PUBLIC ${PROJECT_SOURCE_DIR}
                                                    "${PROJECT_PATH}/Include")
	target_link_libraries(${PROJECT_NAME} debug ${OpenCV_LIBS} optimized
							${OpenCV_LIBS} )
    target_link_libraries(${PROJECT_NAME} nppc nppial nppicc nppidei nppif nppig nppim nppist nppisu nppitc npps)
else()
    target_include_directories(${PROJECT_NAME} PUBLIC ${PROJECT_SOURCE_DIR}
                                                    ${PROJECT_PATH}/Include) #path of include
    target_link_libraries(${PROJECT_NAME} ${OpenCV_LIBS} )
    target_link_libraries(${PROJECT_NAME} boost_thread)
  # Linux下的安装部署
  ## -> install *.dll or *.so
  #install(TARGETS ${PROJECT_NAME} LIBRARY DESTINATION ${PROJECT_SOURCE_DIR}/../../../bin_linux)

  # # -> install *.lib or *.a
  #  install(TARGETS ${PROJECT_NAME} ARCHIVE DESTINATION ${PROJECT_SOURCE_DIR}/../../../bin_linux)
endif(WIN32)
set_target_properties(${PROJECT_NAME} PROPERTIES POSITION_INDEPENDENT_CODE ON)


# Request that particles be built with -std=c++11
# As this is a public compile feature anything that links to particles
# will also build with -std=c++11
target_compile_features(${PROJECT_NAME}  PUBLIC cxx_std_11)

# We need to explicitly state that we need all CUDA files in the particle
# library to be built with -dc as the member functions could be called by
# other libraries and executables
# set_target_properties( ${PROJECT_NAME} PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
# target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_11)
# set_target_properties(${PROJECT_NAME} PROPERTIES POSITION_INDEPENDENT_CODE ON)
# set_target_properties(${PROJECT_NAME} PROPERTIES CUDA_RESOLVE_DEVICE_SYMBOLS ON)